<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    ws = new WebSocket("ws://zp.yunhe168.com:8082");
    ws.onopen = function() {
        alert("连接成功");
        var a='{"user_id":1,"user_id2":2,"type":1}';
        ws.send(a);
        alert("给服务端发送一个字符串"+a);
    };
    ws.onmessage = function(e) {
        alert("收到服务端的消息：" + e.data);
    };

    function send_message(){
        ws.send('{"user_id":1,"user_id2":2,"type":2}')
    }

</script>

<span onclick="send_message()">发送信息</span>
</body>
</html>